package net.pinnoocle.playcommon.utils;

import java.math.BigInteger;
import java.security.MessageDigest;

/**
 * 加密工具类
 *
 * @author ye
 * @Description
 * @create 2021-09-01 16:19
 */
public class EncryptUtils {

  /**
   * sha512
   * @param input
   * @return
   */
  public static String sha512(final String input) {
    try {
      MessageDigest md = MessageDigest.getInstance("SHA-512");
      byte[] messageDigest = md.digest(input.getBytes());
      BigInteger no = new BigInteger(1, messageDigest);
      StringBuilder hashText = new StringBuilder(no.toString(16));
      int maxLength = 128;
      while (hashText.length() < maxLength) {
        hashText.insert(0, "0");
      }
      return hashText.toString();
    } catch (Exception e) {
      System.out.println("加密字符串出错"+e.getMessage());
    }
    return "";
  }
}
